package com.rhb.erp.hr.department.bean;

import java.util.*;

public class Department implements java.io.Serializable {

	public Department() {
	}

	private String departmentPk;
	private String departmentName;
	private String nameMap;
	private Set children = new HashSet();
	private Department parent;

	public void setDepartmentPk(String departmentPk) {
		this.departmentPk = departmentPk;
	}

	public String getDepartmentPk() {
		return this.departmentPk;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public String getDepartmentName() {
		return this.departmentName;
	}

	public boolean isLeaf(){
		return children==null || children.size()==0;
	}
	
	public boolean isRoot(){
		return parent==null;
	}
	
	public boolean hasChildren(){
		return children.size()>0;
	}
	
	public void addChild(Department child){
		child.setParent(this);
		children.add(child);
	}
	
	public void removeChild(Department child){
		children.remove(child);
	}
	
	public void clearChild(){
		children.clear();
	}
	
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((departmentPk == null) ? 0 : departmentPk.hashCode());
		result = prime * result
				+ ((departmentName == null) ? 0 : departmentName.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;

		if (obj == null)
			return false;

		if (getClass() != obj.getClass())
			return false;

		final Department other = (Department) obj;

		if (departmentPk == null) {
			if (other.departmentPk != null)
				return false;
		} else if (!departmentPk.equals(other.departmentPk))
			return false;
		if (departmentName == null) {
			if (other.departmentName != null)
				return false;
		} else if (!departmentName.equals(other.departmentName))
			return false;
		return true;
	}

	public Set getChildren() {
		return children;
	}

	public void setChildren(Set children) {
		this.children = children;
	}

	public Department getParent() {
		return parent;
	}

	public void setParent(Department parent) {
		this.parent = parent;
	}

	public String getNameMap() {
		return nameMap;
	}

	public void setNameMap(String nameMap) {
		this.nameMap = nameMap;
	}
}
